package yunhe.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import yunhe.biz.IProcureBiz;
import yunhe.biz.impl.CusBizImpl;
import yunhe.biz.impl.ProcureBizImpl;
import yunhe.entity.Customer;
import yunhe.entity.Product;
@WebServlet(name="AddCustomerServlet",urlPatterns="/AddCustomerServlet")
public class AddCustomerServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		String cusId=request.getParameter("cusId");
		String cusName=request.getParameter("cusName");
		String cusEmail=request.getParameter("cusEmail");
		String cusAddr=request.getParameter("cusAddr");
		String cusTel=request.getParameter("cusTel");
		String cusPhone=request.getParameter("cusPhone");
		String cusFax=request.getParameter("cusFax");
		String cusBank=request.getParameter("cusBank");
		String cusAccount=request.getParameter("cusAccount");
		String cusTaxNum=request.getParameter("cusTaxNum");
		String cusLinkName=request.getParameter("cusLinkName");
		Customer customer=new Customer(cusName, cusEmail, cusAddr, cusTel, cusPhone, cusFax, cusBank, cusAccount, cusTaxNum, cusLinkName);
		customer.setCusId(cusId);
		CusBizImpl biz=new CusBizImpl();
		PrintWriter out=response.getWriter();
		if(biz.addCustomer(customer)){
			out.print("<script>alert('添加客户成功');location.href='/purchase/addProduct.jsp'</script>");
		}else{
			out.print("<script>alert('添加客户失败');location.href='/purchase/addProduct.jsp'</script>");
		}
	}
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		doGet(req, resp);
	}
}
